package com.example.lotteryticketdev.tool;

import com.alibaba.fastjson.JSONObject;
import com.example.lotteryticketdev.entity.LuckyBall;
import com.example.lotteryticketdev.entity.SpiderResult;

import java.io.*;
import java.util.List;

public class JsonToObjectTool {

    public static List<LuckyBall> getLuckyBallList(String path){
        Reader reader = null;
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();

        try {
            reader = new FileReader(path);
            br = new BufferedReader(reader);
            String line = null;
            while ( (line = br.readLine()) != null ){
                sb.append(line);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            MyClose.closeIO(br,reader);
        }
        SpiderResult spiderResult = JSONObject.parseObject(sb.toString(), SpiderResult.class);
        return spiderResult.getResult();
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        List<LuckyBall> luckyBallList = getLuckyBallList("D:\\dev\\ideaProject\\lottery-ticket-dev\\src\\main\\resources\\static\\json\\b.json");
        System.out.println("luckyBall = " + luckyBallList.get(30));
        long end = System.currentTimeMillis();
        System.out.println("===>耗费"+ (end - start) * 1.0 / 1000 + "秒");
    }
}
